import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
import { HttpHelper } from '../../Helper/HttpHelper';
import { DtoResultObj } from '../../Model/DtoRec/DtoResult';

@Component({
  selector: 'input-select-two',
  templateUrl: './input-select-two.component.html'
})
export class InputSelectTwoComponent implements OnInit {

  /**
   * 第一接口地址
   */
  @Input()
  FirstApiUrl: string
  /**
   * 第一个主键名
   */
  @Input()
  FirstKey: string
  /**
   * 第二接口地址
   */
  @Input()
  SecondtApiUrl: string

 
  // 传入的值
  private _myFirstModel;

  @Input()
  get myFirstModel() {
    return this._myFirstModel;
  }

  set myFirstModel(value) {
    this._myFirstModel = value;
  }

  /**
  * 自定义model变量
  */
  private _myModel;
  /**
   * 返回父组件变化后的值
   */
  @Input()
  get myModel() {
    return this._myModel;
  }
  /**
   * 组件值产生变化后父组件改变
   * @param value
   */
  set myModel(value) {
    this._myModel = value;
    console.log(2222);
    console.log(value)
    this.myModelChange.emit(value);
  }


  @Input()
  PostEnt: any


  @Output()
  myModelChange: EventEmitter<any> = new EventEmitter();

  /**
   * 第一个数据
   */
  ListData1: any = [];

  /**
   * 第一个数据
   */
  ListData2: any = [];
  constructor(
    public httpHelper: HttpHelper,
  ) {

  }

  ngOnInit() {
    console.log("input-select-two的参数")
    console.log("FirstApiUrl" + this.FirstApiUrl);
    console.log("SecondtApiUrl:" + this.SecondtApiUrl);
    this.LoadSelectOption();
  }
  changeFrist() {
    
    this.httpHelper.Post(this.SecondtApiUrl, { Key: this.myFirstModel }).then((x: DtoResultObj<any>) => {
      if (x.success) {
        this.ListData2 = x.dataList;
      }
      else {
      }
    });
  }

  LoadSelectOption() {

    this.httpHelper.Post(this.FirstApiUrl, this.PostEnt).then((x: DtoResultObj<any>) => {
      if (x.success) {
        this.ListData1 = x.dataList;
         this.changeFrist();
      }
      else {
      }
    });
  }



}
